package com.neusoft.zqygbc.neusoft_wenda.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.neusoft.zqygbc.neusoft_wenda.R;
import com.neusoft.zqygbc.neusoft_wenda.adapter.CollectAdapter;
import com.neusoft.zqygbc.neusoft_wenda.base.RetrofitCallback;
import com.neusoft.zqygbc.neusoft_wenda.javeBean.CollectList;
import com.neusoft.zqygbc.neusoft_wenda.javeBean.QuestionEntity;
import com.neusoft.zqygbc.neusoft_wenda.model.CollectModel;

import java.util.List;

import retrofit2.Call;

public class MyCollectActivity extends BaseAvtivity {

    private ImageView mycollect_return;
    private XRecyclerView mycollect_xrv;
    private Intent intent;
    private CollectModel collectModel;
    private Call call;
    private RetrofitCallback<CollectList> collectListCallback;

    @Override
    void initViews() {
        setLayout(R.layout.activity_my_collect);
        intent = getIntent();
        mycollect_return = (ImageView) findViewById(R.id.mycollect_return);
        mycollect_xrv = (XRecyclerView) findViewById(R.id.mycollect_xrv);
        mycollect_xrv.setLayoutManager(new LinearLayoutManager(MyCollectActivity.this));
    }

    @Override
    void initEvents() {
        mycollect_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    @Override
    void initData() {
        collectModel = new CollectModel();
        call = collectModel.collectlist(intent.getStringExtra("user_id"));
        collectListCallback = new RetrofitCallback<CollectList>() {
            @Override
            public void onResponse(CollectList collectList) {
                List<QuestionEntity> questionEntity = collectList.getQuestion();
                mycollect_xrv.setAdapter(new CollectAdapter(MyCollectActivity.this, questionEntity, R.layout.cardview_mycollect));
            }
        };
        collectModel.bindCallback(call, collectListCallback);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initViews();
        initEvents();
        initData();
    }
}
